package com.jiyi.activity.datainput.sm;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.jiyi.activity.datainput.DIBaseMorePicActivity;
import com.jiyi.bean.SingleImageBean;
import com.jiyi.bean.datainput.new_input.BaseCheck;
import com.jiyi.bean.datainput.new_input.FireEquipBean;
import com.jiyi.exception.SampleProgressObserver;
import com.jiyi.inteface.DownloadPicOverInterface;
import com.jiyi.retrofit.HttpMethods;
import com.jiyi.widget.MultiLineRadioGroup;
import com.jiyi.widget.NoScrollGridView;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.base.AppMediaType;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.maintenance.utils.UserInfoUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.MultipartBody;

/**
 * Created by Administrator on 2018/3/22.
 */

public class FireEquipActivity extends DIBaseMorePicActivity implements DownloadPicOverInterface {
    /* 头部 */
    @BindView(R.id.tvBack)
    TextView tvBack;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvSearch)
    TextView tvSearch;

    @BindView(R.id.rgEquipWorkIsOK)
    MultiLineRadioGroup rgEquipWorkIsOK;
    @BindView(R.id.etEquipWorkProblem)
    EditText etEquipWorkProblem;
    @BindView(R.id.etEquipWorkMeasure)
    EditText etEquipWorkMeasure;

    @BindView(R.id.rgAutoWaterSysIsOk)
    MultiLineRadioGroup rgAutoWaterSysIsOk;


    @BindView(R.id.etAutoWaterSysProblem)
    EditText etAutoWaterSysProblem;
    @BindView(R.id.etAutoWaterSysMeasure)
    EditText etAutoWaterSysMeasure;

    @BindView(R.id.rgAutoAlarmSysIsOk)
    MultiLineRadioGroup rgAutoAlarmSysIsOk;
    @BindView(R.id.etAutoAlarmSysProblem)
    EditText etAutoAlarmSysProblem;
    @BindView(R.id.etAutoAlarmSysMeasure)
    EditText etAutoAlarmSysMeasure;

    @BindView(R.id.rgHydrantIsOk)
    MultiLineRadioGroup rgHydrantIsOk;
    @BindView(R.id.etHydrantProblem)
    EditText etHydrantProblem;
    @BindView(R.id.etHydrantMeasure)
    EditText etHydrantMeasure;

    @BindView(R.id.rgSmokeControlIsOk)
    MultiLineRadioGroup rgSmokeControlIsOk;

    @BindView(R.id.etSmokeControlProblem)
    EditText etSmokeControlProblem;
    @BindView(R.id.etSmokeControlMeasure)
    EditText etSmokeControlMeasure;

    @BindView(R.id.rgBroadcastIsOk)
    MultiLineRadioGroup rgBroadcastIsOk;
    @BindView(R.id.etBroadcastProblem)
    EditText etBroadcastProblem;
    @BindView(R.id.etBroadcastMeasure)
    EditText etBroadcastMeasure;

    @BindView(R.id.rgLightingIsOk)
    MultiLineRadioGroup rgLightingIsOk;
    @BindView(R.id.etLightingProblem)
    EditText etLightingProblem;
    @BindView(R.id.etLightingMeasure)
    EditText etLightingMeasure;

    @BindView(R.id.rgFireLiftIsOk)
    MultiLineRadioGroup rgFireLiftIsOk;
    @BindView(R.id.etFireLiftProblem)
    EditText etFireLiftProblem;
    @BindView(R.id.etFireLiftMeasure)
    EditText etFireLiftMeasure;

    @BindView(R.id.rgOtherIsOk)
    RadioGroup rgOtherIsOk;
    @BindView(R.id.rbOtherYes)
    RadioButton rbOtherYes;
    @BindView(R.id.rbOtherMalfunction)
    RadioButton rbOtherMalfunction;
    @BindView(R.id.rbOtherDamage)
    RadioButton rbOtherDamage;
    @BindView(R.id.rbOtherParalysis)
    RadioButton rbOtherParalysis;
    @BindView(R.id.rbOther2)
    RadioButton rbOther2;
    @BindView(R.id.etOtherProblem)
    EditText etOtherProblem;
    @BindView(R.id.etOtherMeasure)
    EditText etOtherMeasure;

    String build_id;
    int mEquipWorkIsOK, mAutoWaterSysIsOk, mAutoAlarmSysIsOk, mHydrantIsOk, mSmokeControlIsOk, mBroadcastIsOk, mLightingIsOk, mFireLiftIsOk, mOtherIsOk;

    @BindView(R.id.gvEquipWork)
    NoScrollGridView gvEquipWork;
    @BindView(R.id.gvAutoWaterSys)
    NoScrollGridView gvAutoWaterSys;
    @BindView(R.id.gvAutoAlarmSys)
    NoScrollGridView gvAutoAlarmSys;
    @BindView(R.id.gvHydrant)
    NoScrollGridView gvHydrant;
    @BindView(R.id.gvSmokeControl)
    NoScrollGridView gvSmokeControl;
    @BindView(R.id.gvBroadcast)
    NoScrollGridView gvBroadcast;
    @BindView(R.id.gvLighting)
    NoScrollGridView gvLighting;
    @BindView(R.id.gvFireLift)
    NoScrollGridView gvFireLift;
    @BindView(R.id.gvOther)
    NoScrollGridView gvOther;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fire_equip);
        ButterKnife.bind(this);
        init();
    }

    public void init() {
        getIntentData();
        setTop();
        setViewStatus();
        getData();
        super.setDownloadPicOverInterface(this);
    }

    private void getIntentData() {
        build_id = getIntent().getStringExtra("build_no");
        if (TextUtils.isEmpty(build_id))
            build_id = "";
    }

    private void setTop() {
        tvTitle.setText("消防设施设备是否完好有效");
        tvSearch.setCompoundDrawables(null, null, null, null);
        tvSearch.setText("保存");
    }

    public void setViewStatus() {
        rgEquipWorkIsOK.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mEquipWorkIsOK = 1;
                } else if (position == 1) {
                    mEquipWorkIsOK = 0;
                } else if (position == 2) {
                    mEquipWorkIsOK = 2;
                } else if (position == 3) {
                    mEquipWorkIsOK = 3;
                } else {
                    mEquipWorkIsOK = 4;
                }
            }
        });
        rgEquipWorkIsOK.setItemChecked(4);

        rgAutoWaterSysIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mAutoWaterSysIsOk = 1;
                } else if (position == 1) {
                    mAutoWaterSysIsOk = 0;
                } else if (position == 2) {
                    mAutoWaterSysIsOk = 2;
                } else if (position == 3) {
                    mAutoWaterSysIsOk = 3;
                } else {
                    mAutoWaterSysIsOk = 4;
                }
            }
        });
        rgAutoWaterSysIsOk.setItemChecked(4);

        rgAutoAlarmSysIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mAutoAlarmSysIsOk = 1;
                } else if (position == 1) {
                    mAutoAlarmSysIsOk = 0;
                } else if (position == 2) {
                    mAutoAlarmSysIsOk = 2;
                } else if (position == 3) {
                    mAutoAlarmSysIsOk = 3;
                } else {
                    mAutoAlarmSysIsOk = 4;
                }
            }
        });
        rgAutoAlarmSysIsOk.setItemChecked(4);

        rgHydrantIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mHydrantIsOk = 1;
                } else if (position == 1) {
                    mHydrantIsOk = 0;
                } else if (position == 2) {
                    mHydrantIsOk = 2;
                } else if (position == 3) {
                    mHydrantIsOk = 3;
                } else {
                    mHydrantIsOk = 4;
                }
            }
        });
        rgHydrantIsOk.setItemChecked(4);

        rgSmokeControlIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mSmokeControlIsOk = 1;
                } else if (position == 1) {
                    mSmokeControlIsOk = 0;
                } else if (position == 2) {
                    mSmokeControlIsOk = 2;
                } else if (position == 3) {
                    mSmokeControlIsOk = 3;
                } else {
                    mSmokeControlIsOk = 4;
                }
            }
        });
        rgSmokeControlIsOk.setItemChecked(4);

        rgBroadcastIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mBroadcastIsOk = 1;
                } else if (position == 1) {
                    mBroadcastIsOk = 0;
                } else if (position == 2) {
                    mBroadcastIsOk = 2;
                } else if (position == 3) {
                    mBroadcastIsOk = 3;
                } else {
                    mBroadcastIsOk = 4;
                }
            }
        });
        rgBroadcastIsOk.setItemChecked(4);

        rgLightingIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mLightingIsOk = 1;
                } else if (position == 1) {
                    mLightingIsOk = 0;
                } else if (position == 2) {
                    mLightingIsOk = 2;
                } else if (position == 3) {
                    mLightingIsOk = 3;
                } else {
                    mLightingIsOk = 4;
                }
            }
        });
        rgLightingIsOk.setItemChecked(4);

        rgFireLiftIsOk.setOnCheckChangedListener(new MultiLineRadioGroup.OnCheckedChangedListener() {
            @Override
            public void onItemChecked(MultiLineRadioGroup group, int position, boolean checked) {
                if (position == 0) {
                    mFireLiftIsOk = 1;
                } else if (position == 1) {
                    mFireLiftIsOk = 0;
                } else if (position == 2) {
                    mFireLiftIsOk = 2;
                } else if (position == 3) {
                    mFireLiftIsOk = 3;
                } else {
                    mFireLiftIsOk = 4;
                }
            }
        });
        rgFireLiftIsOk.setItemChecked(4);

        rgOtherIsOk.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rbOtherYes) {
                    mOtherIsOk = 1;
                } else if (checkedId == R.id.rbOtherMalfunction) {
                    mOtherIsOk = 0;
                } else if (checkedId == R.id.rbOtherDamage) {
                    mOtherIsOk = 2;
                } else if (checkedId == R.id.rbOtherParalysis) {
                    mOtherIsOk = 3;
                } else {
                    mOtherIsOk = 4;

                }
            }
        });

    }


    public void getData() {
        HttpMethods.getInstance().getFireEquipInfo(UserInfoUtil.getCurrentUserAccessToken(), build_id, 2)
                .subscribe(new SampleProgressObserver<FireEquipBean>(this) {
                    @Override
                    public void onNext(FireEquipBean fireEquipBean) {
                        if (fireEquipBean == null || "".equals(fireEquipBean.getGson_null())) {
                            fireEquipBean = new FireEquipBean();
                            BaseCheck bc1 = new BaseCheck();
                            bc1.setIs_ok(1);
                            bc1.setProblem("");
                            bc1.setMeasures("");
                            fireEquipBean.setControl_room_equipment(bc1);
                            BaseCheck bc2 = new BaseCheck();
                            bc2.setIs_ok(1);
                            bc2.setProblem("");
                            bc2.setMeasures("");
                            fireEquipBean.setSprinkler_system(bc2);
                            BaseCheck bc3 = new BaseCheck();
                            bc3.setIs_ok(1);
                            bc3.setProblem("");
                            bc3.setMeasures("");
                            fireEquipBean.setFire_alarm_system(bc3);
                            BaseCheck bc4 = new BaseCheck();
                            bc4.setIs_ok(1);
                            bc4.setProblem("");
                            bc4.setMeasures("");
                            fireEquipBean.setInside_hydrant(bc4);
                            BaseCheck bc5 = new BaseCheck();
                            bc5.setIs_ok(1);
                            bc5.setProblem("");
                            bc5.setMeasures("");
                            fireEquipBean.setMechanical_smoke_control(bc5);
                            BaseCheck bc6 = new BaseCheck();
                            bc6.setIs_ok(1);
                            bc6.setProblem("");
                            bc6.setMeasures("");
                            fireEquipBean.setEmergent_broadcast(bc6);
                            BaseCheck bc7 = new BaseCheck();
                            bc7.setIs_ok(1);
                            bc7.setProblem("");
                            bc7.setMeasures("");
                            fireEquipBean.setLighting_evacuation_indicator(bc7);
                            BaseCheck bc8 = new BaseCheck();
                            bc8.setIs_ok(1);
                            bc8.setProblem("");
                            bc8.setMeasures("");
                            fireEquipBean.setFire_elevator(bc8);
                            BaseCheck bc9 = new BaseCheck();
                            bc9.setIs_ok(1);
                            bc9.setProblem("");
                            bc9.setMeasures("");
                            fireEquipBean.setOther(bc9);
                            fireEquipBean.setNo_edit(1);
                        }

                        fillData(fireEquipBean);
                    }
                });
    }

    private void fillData(FireEquipBean bean) {

        System.out.println("bean.getControl_room_equipment().getIs_ok():" + bean.getControl_room_equipment().getIs_ok());

        if (bean.getControl_room_equipment().getIs_ok() == 0) {
            rgEquipWorkIsOK.setItemChecked(1);
        } else if (bean.getControl_room_equipment().getIs_ok() == 1) {
            rgEquipWorkIsOK.setItemChecked(0);
        } else if (bean.getControl_room_equipment().getIs_ok() == 2) {
            rgEquipWorkIsOK.setItemChecked(2);
        } else if (bean.getControl_room_equipment().getIs_ok() == 3) {
            rgEquipWorkIsOK.setItemChecked(3);
        } else if (bean.getControl_room_equipment().getIs_ok() == 4){
            rgEquipWorkIsOK.setItemChecked(4);
        }

        etEquipWorkProblem.setText(bean.getControl_room_equipment().getProblem());
        etEquipWorkMeasure.setText(bean.getControl_room_equipment().getMeasures());

        if (bean.getSprinkler_system().getIs_ok() == 0) {
            rgAutoWaterSysIsOk.setItemChecked(1);
        } else if (bean.getSprinkler_system().getIs_ok() == 1) {
            rgAutoWaterSysIsOk.setItemChecked(0);
        } else if (bean.getSprinkler_system().getIs_ok() == 2) {
            rgAutoWaterSysIsOk.setItemChecked(2);
        } else if (bean.getSprinkler_system().getIs_ok() == 3) {
            rgAutoWaterSysIsOk.setItemChecked(3);
        } else if (bean.getSprinkler_system().getIs_ok() == 4){
            rgAutoWaterSysIsOk.setItemChecked(4);
        }

        etAutoWaterSysProblem.setText(bean.getSprinkler_system().getProblem());
        etAutoWaterSysMeasure.setText(bean.getSprinkler_system().getMeasures());

        if (bean.getFire_alarm_system().getIs_ok() == 0) {
            rgAutoAlarmSysIsOk.setItemChecked(1);
        } else if (bean.getFire_alarm_system().getIs_ok() == 1) {
            rgAutoAlarmSysIsOk.setItemChecked(0);
        } else if (bean.getFire_alarm_system().getIs_ok() == 2) {
            rgAutoAlarmSysIsOk.setItemChecked(2);
        } else if (bean.getFire_alarm_system().getIs_ok() == 3) {
            rgAutoAlarmSysIsOk.setItemChecked(3);
        } else if (bean.getFire_alarm_system().getIs_ok() == 4){
            rgAutoAlarmSysIsOk.setItemChecked(4);
        }

        etAutoAlarmSysProblem.setText(bean.getFire_alarm_system().getProblem());
        etAutoAlarmSysMeasure.setText(bean.getFire_alarm_system().getMeasures());

        if (bean.getInside_hydrant().getIs_ok() == 0) {
            rgHydrantIsOk.setItemChecked(1);
        } else if (bean.getInside_hydrant().getIs_ok() == 1) {
            rgHydrantIsOk.setItemChecked(0);
        } else if (bean.getInside_hydrant().getIs_ok() == 2) {
            rgHydrantIsOk.setItemChecked(2);
        } else if (bean.getInside_hydrant().getIs_ok() == 3) {
            rgHydrantIsOk.setItemChecked(3);
        } else if (bean.getInside_hydrant().getIs_ok() == 4){
            rgHydrantIsOk.setItemChecked(4);
        }

        etHydrantProblem.setText(bean.getInside_hydrant().getProblem());
        etHydrantMeasure.setText(bean.getInside_hydrant().getMeasures());

        if (bean.getMechanical_smoke_control().getIs_ok() == 0) {
            rgSmokeControlIsOk.setItemChecked(1);
        } else if (bean.getMechanical_smoke_control().getIs_ok() == 1) {
            rgSmokeControlIsOk.setItemChecked(0);
        } else if (bean.getMechanical_smoke_control().getIs_ok() == 2) {
            rgSmokeControlIsOk.setItemChecked(2);
        } else if (bean.getMechanical_smoke_control().getIs_ok() == 3) {
            rgSmokeControlIsOk.setItemChecked(3);
        } else if (bean.getMechanical_smoke_control().getIs_ok() == 4){
            rgSmokeControlIsOk.setItemChecked(4);
        }

        etSmokeControlProblem.setText(bean.getMechanical_smoke_control().getProblem());
        etSmokeControlMeasure.setText(bean.getMechanical_smoke_control().getMeasures());

        if (bean.getEmergent_broadcast().getIs_ok() == 0) {
            rgBroadcastIsOk.setItemChecked(1);
        } else if (bean.getEmergent_broadcast().getIs_ok() == 1) {
            rgBroadcastIsOk.setItemChecked(0);
        } else if (bean.getEmergent_broadcast().getIs_ok() == 2) {
            rgBroadcastIsOk.setItemChecked(2);
        } else if (bean.getEmergent_broadcast().getIs_ok() == 3) {
            rgBroadcastIsOk.setItemChecked(3);
        } else if (bean.getEmergent_broadcast().getIs_ok() == 4) {
            rgBroadcastIsOk.setItemChecked(4);
        }

        etBroadcastProblem.setText(bean.getEmergent_broadcast().getProblem());
        etBroadcastMeasure.setText(bean.getEmergent_broadcast().getMeasures());

        if (bean.getLighting_evacuation_indicator().getIs_ok() == 0) {
            rgLightingIsOk.setItemChecked(1);
        } else if (bean.getLighting_evacuation_indicator().getIs_ok() == 1) {
            rgLightingIsOk.setItemChecked(0);
        } else if (bean.getLighting_evacuation_indicator().getIs_ok() == 2) {
            rgLightingIsOk.setItemChecked(2);
        } else if (bean.getLighting_evacuation_indicator().getIs_ok() == 3) {
            rgLightingIsOk.setItemChecked(3);
        }  else if (bean.getEmergent_broadcast().getIs_ok() == 4){
            rgLightingIsOk.setItemChecked(4);
        }

        etLightingProblem.setText(bean.getLighting_evacuation_indicator().getProblem());
        etLightingMeasure.setText(bean.getLighting_evacuation_indicator().getMeasures());

        if (bean.getFire_elevator().getIs_ok() == 0) {
            rgFireLiftIsOk.setItemChecked(1);
        } else if (bean.getFire_elevator().getIs_ok() == 1) {
            rgFireLiftIsOk.setItemChecked(0);
        } else if (bean.getFire_elevator().getIs_ok() == 2) {
            rgFireLiftIsOk.setItemChecked(2);
        } else if (bean.getFire_elevator().getIs_ok() == 3) {
            rgFireLiftIsOk.setItemChecked(3);
        } else if (bean.getFire_elevator().getIs_ok() == 4){
            rgFireLiftIsOk.setItemChecked(4);
        }

        etFireLiftProblem.setText(bean.getFire_elevator().getProblem());
        etFireLiftMeasure.setText(bean.getFire_elevator().getMeasures());

        if (bean.getOther().getIs_ok() == 1) {
            rbOtherYes.setChecked(true);
        } else if (bean.getOther().getIs_ok() == 0) {
            rbOtherMalfunction.setChecked(true);
        } else if (bean.getOther().getIs_ok() == 2) {
            rbOtherDamage.setChecked(true);
        } else if (bean.getOther().getIs_ok() == 3){
            rbOtherParalysis.setChecked(true);
        } else if (bean.getOther().getIs_ok() == 4) {
            rbOther2.setChecked(true);
        }

        etOtherProblem.setText(bean.getOther().getProblem());
        etOtherMeasure.setText(bean.getOther().getMeasures());
        if (bean.getNo_edit() == 1) {
            tvSearch.setVisibility(View.VISIBLE);
        } else {
            tvSearch.setVisibility(View.INVISIBLE);
        }

        initGridViewList(bean);
    }

    void initGridViewList(FireEquipBean fireEquipBean) {
        List<SingleImageBean> singleImageBeans = new ArrayList<SingleImageBean>();

        SingleImageBean s1 = new SingleImageBean();
        s1.setPosition(0);
        s1.setDelModel(false);
        s1.setGridView(gvEquipWork);
        s1.setImageList(fireEquipBean.getControl_room_equipment().getImage());
        singleImageBeans.add(s1);

        SingleImageBean s2 = new SingleImageBean();
        s2.setPosition(1);
        s2.setDelModel(false);
        s2.setGridView(gvAutoWaterSys);
        s2.setImageList(fireEquipBean.getSprinkler_system().getImage());
        singleImageBeans.add(s2);

        SingleImageBean s3 = new SingleImageBean();
        s3.setPosition(2);
        s3.setDelModel(false);
        s3.setGridView(gvAutoAlarmSys);
        s3.setImageList(fireEquipBean.getFire_alarm_system().getImage());
        singleImageBeans.add(s3);

        SingleImageBean s4 = new SingleImageBean();
        s4.setPosition(3);
        s4.setDelModel(false);
        s4.setGridView(gvHydrant);
        s4.setImageList(fireEquipBean.getInside_hydrant().getImage());
        singleImageBeans.add(s4);

        SingleImageBean s5 = new SingleImageBean();
        s5.setPosition(4);
        s5.setDelModel(false);
        s5.setGridView(gvSmokeControl);
        s5.setImageList(fireEquipBean.getMechanical_smoke_control().getImage());
        singleImageBeans.add(s5);

        SingleImageBean s6 = new SingleImageBean();
        s6.setPosition(5);
        s6.setDelModel(false);
        s6.setGridView(gvBroadcast);
        s6.setImageList(fireEquipBean.getEmergent_broadcast().getImage());
        singleImageBeans.add(s6);

        SingleImageBean s7 = new SingleImageBean();
        s7.setPosition(6);
        s7.setDelModel(false);
        s7.setGridView(gvLighting);
        s7.setImageList(fireEquipBean.getLighting_evacuation_indicator().getImage());
        singleImageBeans.add(s7);

        SingleImageBean s8 = new SingleImageBean();
        s8.setPosition(7);
        s8.setDelModel(false);
        s8.setGridView(gvFireLift);
        s8.setImageList(fireEquipBean.getFire_elevator().getImage());
        singleImageBeans.add(s8);

        SingleImageBean s9 = new SingleImageBean();
        s9.setPosition(8);
        s9.setDelModel(false);
        s9.setGridView(gvOther);
        s9.setImageList(fireEquipBean.getOther().getImage());
        singleImageBeans.add(s9);

        mulGridViewBean.setSingleImageList(singleImageBeans);
        refreshAdapter();
    }

    private void doPost() {
        Map<String, String> a1 = new HashMap<>();
        a1.put("is_ok", mEquipWorkIsOK + "");
        a1.put("problem", etEquipWorkProblem.getText().toString());
        a1.put("measures", etEquipWorkMeasure.getText().toString());

        Map<String, String> a2 = new HashMap<>();
        a2.put("is_ok", mAutoWaterSysIsOk + "");
        a2.put("problem", etAutoWaterSysProblem.getText().toString());
        a2.put("measures", etAutoWaterSysMeasure.getText().toString());

        Map<String, String> a3 = new HashMap<>();
        a3.put("is_ok", mAutoAlarmSysIsOk + "");
        a3.put("problem", etAutoAlarmSysProblem.getText().toString());
        a3.put("measures", etAutoAlarmSysMeasure.getText().toString());

        Map<String, String> a4 = new HashMap<>();
        a4.put("is_ok", mHydrantIsOk + "");
        a4.put("problem", etHydrantProblem.getText().toString());
        a4.put("measures", etHydrantMeasure.getText().toString());

        Map<String, String> a5 = new HashMap<>();
        a5.put("is_ok", mSmokeControlIsOk + "");
        a5.put("problem", etSmokeControlProblem.getText().toString());
        a5.put("measures", etSmokeControlMeasure.getText().toString());


        Map<String, String> a6 = new HashMap<>();
        a6.put("is_ok", mBroadcastIsOk + "");
        a6.put("problem", etBroadcastProblem.getText().toString());
        a6.put("measures", etBroadcastMeasure.getText().toString());

        Map<String, String> a7 = new HashMap<>();
        a7.put("is_ok", mLightingIsOk + "");
        a7.put("problem", etLightingProblem.getText().toString());
        a7.put("measures", etLightingMeasure.getText().toString());

        Map<String, String> a8 = new HashMap<>();
        a8.put("is_ok", mFireLiftIsOk + "");
        a8.put("problem", etFireLiftProblem.getText().toString());
        a8.put("measures", etFireLiftMeasure.getText().toString());

        Map<String, String> a9 = new HashMap<>();
        a9.put("is_ok", mOtherIsOk + "");
        a9.put("problem", etOtherProblem.getText().toString());
        a9.put("measures", etOtherMeasure.getText().toString());

        Map<String, Map<String, String>> dataParams = new HashMap<>();
        dataParams.put("control_room_equipment",        a1);
        dataParams.put("sprinkler_system",              a2);
        dataParams.put("fire_alarm_system",             a3);
        dataParams.put("inside_hydrant",                a4);
        dataParams.put("mechanical_smoke_control",      a5);
        dataParams.put("emergent_broadcast",            a6);
        dataParams.put("lighting_evacuation_indicator", a7);
        dataParams.put("fire_elevator",                 a8);
        dataParams.put("other",                         a9);

        MultipartBody.Builder builder = new MultipartBody.Builder();

        putBody(builder, AppConfig.ACCESS_TOKEN, AppMediaType.TEXT, UserInfoUtil.getCurrentUserAccessToken());
        putBody(builder, "build_id", AppMediaType.TEXT, build_id);
        putBody(builder, "type", AppMediaType.TEXT, 1 + "");
        putBody(builder, "data", AppMediaType.TEXT, new Gson().toJson(dataParams));
        putBody(builder, "action_type", AppMediaType.TEXT, "facilities_good_condition");


        // 图片数组
        File file;
        int size = mulGridViewBean.getSingleImageList().size();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < mulGridViewBean.getSingleImageList().get(i).getImageList().size(); j++) {
                if (mulGridViewBean.getSingleImageList().get(i).getImageList().get(j).contains("http")) {
                    Log.e("ttt     ", mulGridViewBean.getSingleImageList().get(i).getImageList().get(j) + "\n");
                    continue;
                } else {
                    file = new File(mulGridViewBean.getSingleImageList().get(i).getImageList().get(j));
                    if (i == 0) {
                        putBody(builder, "image*control_room_equipment[]", AppMediaType.JPG, file);
                    } else if (i == 1) {
                        putBody(builder, "image*sprinkler_system[]", AppMediaType.JPG, file);
                    } else if (i == 2) {
                        putBody(builder, "image*fire_alarm_system[]", AppMediaType.JPG, file);
                    }
                    else if (i == 3) {
                        putBody(builder, "image*inside_hydrant[]", AppMediaType.JPG, file);
                    }
                    else if (i == 4) {
                        putBody(builder, "image*mechanical_smoke_control[]", AppMediaType.JPG, file);
                    }
                    else if (i == 5) {
                        putBody(builder, "image*emergent_broadcast[]", AppMediaType.JPG, file);
                    }
                    else if (i == 6) {
                        putBody(builder, "image*lighting_evacuation_indicator[]", AppMediaType.JPG, file);
                    }
                    else if (i == 7) {
                        putBody(builder, "image*fire_elevator[]", AppMediaType.JPG, file);
                    }
                    else if (i == 8) {
                        putBody(builder, "image*other[]", AppMediaType.JPG, file);
                    }
                    else {
                        continue;
                    }
                }
            }
        }

        builder.setType(MultipartBody.FORM);
        MultipartBody multipartBody = builder.build();

        HttpMethods.getInstance().postFireEquipInfo(multipartBody)
                .subscribe(new SampleProgressObserver<FireEquipBean>(this) {
                    @Override
                    public void onNext(FireEquipBean fireEquipBean) {
                        ToastUtil.getInstances().showMsg("保存成功");
                    }
                });

    }

    @OnClick({R.id.tvBack, R.id.tvSearch})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvBack:
                finish();
                break;
            case R.id.tvSearch:
                downloadImage();
                break;
            default:
                break;
        }
    }

    @Override
    public void post() {
        doPost();
    }
}
